package com.freewater.javabase.demo.designpattern.command2.undowithstatus.command;

import com.freewater.javabase.demo.designpattern.command2.undowithstatus.receiver.CellingFan;

/**
 * Created by FreeWater on 2017/4/4.
 */
public class CellingFanLowCommand implements Command {

	private CellingFan cellingFan;

	private int prevSpeed;

	public CellingFanLowCommand(CellingFan cellingFan){
		this.cellingFan = cellingFan;
	}

	@Override
	public void execute() {
		this.prevSpeed = this.cellingFan.getSpeed();
		this.cellingFan.low();
	}

	@Override
	public void undo() {
		if(this.prevSpeed == CellingFan.HIGH){
			this.cellingFan.high();
		}else if(this.prevSpeed == CellingFan.MEDIUM){
			this.cellingFan.medium();
		}else if(this.prevSpeed == CellingFan.LOW){
			this.cellingFan.low();
		}else if(this.prevSpeed == CellingFan.OFF){
			this.cellingFan.off();
		}
	}
}
